package org.example.JUC.thread;

import org.example.JUC.stop.myStopThread;

import java.util.concurrent.Callable;

/**
 * @description:
 * @author: farprt
 * @create: 2022-04-25 20:27
 **/
public class thread extends Thread{

    public static Integer num=0;

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"A").start();

        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"B").start();

        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"C").start();

        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"D").start();

        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"E").start();

        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"F").start();

        new Thread(()->{
            try {
                addNum();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(num);
        },"G").start();


    }

    public synchronized static void addNum() throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            Thread.sleep(1);
            num++;
//            System.out.println(Thread.currentThread().getName() + "++");
        }
    }

}

